<template>
  <el-dialog title="工艺路线选择"
             v-if="showFlag"
             :visible.sync="showFlag"
             :modal= false
             width="80%"
             center
  >
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <el-row>
        <el-col :span="8">
          <el-form-item label="工艺路线编号" prop="routeCode">
            <el-input
              v-model="queryParams.vendorCode"
              placeholder="请输入工艺路线编码"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="工艺路线名称" prop="routeName">
            <el-input
              v-model="queryParams.vendorName"
              placeholder="请输入工艺路线名称"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>

    <el-table border v-loading="loading" :data="routeList" @current-change="handleCurrent" @row-dblclick="handleRowDbClick">
      <el-table-column  width="55" align="center" >
        <template v-slot="scope">
          <el-radio v-model="selectedRouteId" :label="scope.row.routeId" @change="handleRowChange(scope.row)">{{""}}</el-radio>
        </template>
      </el-table-column>
      <el-table-column label="工艺路线编码" align="center" prop="routeCode" >
      </el-table-column>
      <el-table-column label="工艺路线名称" align="center" prop="routeName" :show-overflow-tooltip="true"/>
      <el-table-column label="工艺路线说明" align="center" prop="routeDesc" :show-overflow-tooltip="true" />
      <el-table-column label="是否启用" align="center" prop="enableFlag" >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_yes_no" :value="scope.row.enableFlag"/>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remark" :show-overflow-tooltip="true"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            type="text"
            icon="el-icon-view"
            @click="handleView(scope.row)"
            v-hasPermi="['mes:pro:proroute:query']"
          >查看</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="confirmSelect">确 定</el-button>
      <el-button @click="showFlag=false">取 消</el-button>
    </div>

    <el-dialog title="工序详情" v-if="showDialog" :visible.sync="showDialog" :modal= false width="80%" center>
      <el-table v-loading="processLoading" :data="routeprocessList">
        <el-table-column label="序号" align="center" fixed prop="orderNum" />
        <el-table-column label="工序编码" width="120px" fixed align="center" prop="processCode" />
        <el-table-column label="工序名称" width="150px" fixed align="center" prop="processName" />
        <el-table-column label="下一道工序" width="150px"  align="center" prop="nextProcessName" />
        <el-table-column label="与下一道工序关系" width="150px" align="center" prop="linkType">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.mes_link_type" :value="scope.row.linkType"/>
          </template>
        </el-table-column>
        <!--        <el-table-column label="关键工序" width="100px" align="center" prop="keyFlag">
                  <template slot-scope="scope">
                    <dict-tag :options="dict.type.sys_yes_no" :value="scope.row.keyFlag"/>
                  </template>
                </el-table-column>-->
        <el-table-column label="质检确认" width="100px" align="center" prop="isCheck">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.sys_yes_no" :value="scope.row.isCheck"/>
          </template>
        </el-table-column>
        <el-table-column label="准备时间" align="center" prop="defaultPreTime" />
        <el-table-column label="等待时间" align="center" prop="defaultSufTime" />
        <el-table-column label="甘特图显示颜色" align="center" prop="colorCode" >
          <template slot-scope="scope">
            <el-color-picker v-model="scope.row.colorCode" disabled></el-color-picker>
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </el-dialog>

  </el-dialog>
</template>

<script>
import { listProroute } from "@/api/mes/pro/proroute";
import { listRouteprocess } from "@/api/mes/pro/routeprocess";

export default {
  name: "RouteSelect",
  dicts: ['sys_yes_no','mes_vendor_level','mes_link_type'],
  data() {
    return {
      showFlag:false,
      selectedRouteId: undefined,
      selectedRow: undefined,
      // 遮罩层
      loading: true,
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 工艺路线表格数据
      routeList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 工序弹框开关
      showDialog: false,
      // 工序遮罩层
      processLoading: true,
      // 工序表格数据
      routeprocessList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        routeCode: null,
        enableFlag: 'Y',
      },
      // 表单参数
      form: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询供应商列表 */
    getList() {
      this.loading = true;
      listProroute(this.queryParams).then(response => {
        this.routeList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    handleCurrent(row){
      if(row){
        this.selectedRow = row;
      }
    },
    //行双击选中
    handleRowDbClick(row){
      if(row){
        this.selectedRow = row;
        this.$emit('onSelected',this.selectedRow);
        this.showFlag = false;
      }
    },
    // 单选选中数据
    handleRowChange(row) {
      if(row){
        this.selectedRow = row;
      }
    },
    //确定选中
    confirmSelect(){
      if(this.selectedRouteId === null || this.selectedRouteId === 0){
        this.$notify({
          title:'提示',
          type:'warning',
          message: '请至少选择一条数据!'
        });
        return;
      }
      this.$emit('onSelected',this.selectedRow);
      this.showFlag = false;
    },
    // 查看按钮操作
    handleView(row) {
      this.showDialog = true;
      this.processLoading = true;
      var queryParams = {
          pageNum: 1,
          pageSize: 10,
          routeId: row.routeId
      };
      listRouteprocess(queryParams).then(response => {
        this.routeprocessList = response.rows;
        this.total = response.total;
        this.processLoading = false;
      });
    },
  }
};
</script>
